Tag Link | [Net->ReadFrom] | Category | Networking |
---|---|---|---|
Type | Member | Source Available | Yes |
Support | Preferred | Version | 7.0 |
Change | Unchanged | Data Source | Any |
Output Type | Bytes | Security | None |
Implementation | LCAPI | Sets | Lasso 8.5, Lasso 8.0, Lasso 7.0 |
[Net->ReadFrom] is used with UDP connections to read data that has been sent by a remote host. The tag requires a single parameter which is the maximum number of characters to read. The tag will return a pair containing all data which is available in the connection up to the maximum number of characters in the first part and the address of the remote host that sent the data in the second part.
A UDP connection must be bound to a port using [Net->Bind] in order to use the [Net->ReadFrom] tag. The [Net->ReadFrom] tag can be used multiple times to read data from many remote hosts.
<?LassoScript
Variable: 'Connection' = (Net);
$Connection->(SetType: Net_TypeUDP);
$Connection->(Bind: 8000);
Variable: 'Temp' = $Connection->(ReadFrom: 32768);
Variable: 'Data' = $Temp->First;
Variable: 'Host' = $Temp->Second;
...
$Connection->Close;
?>
Required Parameters | |
---|---|
Maximum | The maximum number of characters to read from the connection. |
To connect to a remote server using UDP:
Use the [Net] type and its member tags to send data to a remote server via UDP and then to listen for a response. The following example sends data to an example time server and then listens for the current date and time to be sent back on port 8000.
[Variable: 'myConnection' = (Net)]
[$myConnection->(SetType: Net_TypeUDP)]
[Var: 'Result' = $myConnection->(WriteTo: 'time.example.com', 8000, 'TIME')]
[$myConnection->(Close)]
[Variable: 'myListener' = (Net)]
[$myListener->(SetType: Net_TypeUDP)]
[$myListener->(Bind: 8000)]
[Var: 'Output' = $myListener->(ReadFrom: 32768)]
[$myListener->(Close)]
Time server at [Output: $Output->Second]
reports the time as [Output: $Output->First].
Time server at www.example.com reports the time as 9/23/2003 12:13:35 PM